package com.yjq0714.test3;

import java.util.LinkedList;

public class DelSeven {
    public static int index = 0;//下标
    public static int temp = 1;//计数器
    public static int size = 100;//链表长度
    public static int qq = 0;//已删除长度

    public static void main(String[] args) {
        LinkedList<String> linkedList = new LinkedList<>();
        for (int i = 0; i < 10; i++) {
            linkedList.add("鱼");
            linkedList.add("几");
            linkedList.add("兔");
            linkedList.add("猫");
            linkedList.add("狗");
            linkedList.add("犬");
            linkedList.add("牛");
            linkedList.add("象");
            linkedList.add("狮");
            linkedList.add("虎");
        }
        for (String s : linkedList
        ) {
            System.out.print(s);

        }
        System.out.println("\n");
        while (!linkedList.isEmpty()) {
            //计数器到7就删除该下标的字符，因为链表长度变小，index也需减小一位，删除的长度增加一位。
            if (temp == 7) {
                System.out.println(linkedList.get(index) + "  " + linkedList.size() + "  " + index + "  " + qq);
                linkedList.remove(index);
                temp = 0;
                qq++;
                index--;
            }
            //如果下标小于当前链表长度，继续增加
            if (index <= size - qq - 2) {
                temp++;
                index++;
            } else {
                index = 0;
                temp++;
            }
        }
        if (linkedList.isEmpty()) {
            System.out.println("删除成功！！");
        }
    }
}
